#include <stdio.h>
int bin_search(int arr[], int left, int right, int key)
{
   // int mid = (left + right) / 2;
    while (left <= right)
    {
        int mid = (left + right) / 2;//让mid参与循环
        if (arr[mid] > key)
        {
            right = mid - 1;  
        }
        else if (arr[mid] < key)
        {
            left = mid + 1;
        }
        else 
        {
            return mid;
        }
    }
    return -1;
}
int main()
{
    int  arr[] = {1,2,3,4,5,6,7,8,9};
    int right = sizeof (arr) / sizeof (arr[0]) - 1;
    int r = bin_search (arr, 0, right, 6);
    if (r == -1)
    {
        printf("没找到");
    }
    else 
    {
        printf("%d", r);
    }
    return 0;
}
